<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // 1. 注册提交数据到登录页(直接打开登录页没有数据)
    // 2. 在登录页进行数据解析

    // "http://127.0.0.1:5500/day13/html/login.html?user=a123123&pwd=123123&phone=17386141516&email=1272071496%40qq.com"

    // 参数数据"?user=a123123&pwd=123123&phone=17386141516&email=1272071496%40qq.com"
    // (1) 单条数据以键值对的形式存在(key=value  key描述 value值)
    // (2) 数据之间以 & 分隔

    // 数据解析: 将数据解析为对象 => {user:"xxx",pwd:"xxx","phone":"xxx",email:"xxx"}

    // console.log(location);

    var search = location.search;
    var data = {};
    if(search){ 
        console.log(search);
        var str =search.substring(1);
        console.log(str);

        var list = str.split("&");
        console.log(list);

        for(var i=0;i<list.length;i++){
            var item = list[i];  // 'user=a123123', 'pwd=123123'
            var key = item.split("=")[0]; // "user"  "pwd"
            var val = item.split("=")[1]; // "a123123"
            console.log(item,key,val);

            data[key] = val;
        }

    }else{  //没有数据(直接打开登录页) -> 去注册
        location.href="./register.html"
    }

    console.log(data);

</script>

</html>